/****************************************************
 * Description: Entity for 角色权限
 * Copyright:   Copyright (c) 2013
 * Company:     beiwaionline
 * @author      bfsu
 * @version     1.0
 * @see
	HISTORY
    *  2013-08-08 bfsu Create File
**************************************************/

package com.bfsuol.bfsuolframework.security.dao;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bfsuol.bfsuolframework.core.entity.Entity;
import com.bfsuol.bfsuolframework.core.entity.EntitySupport;
import lombok.Data;
import lombok.experimental.Accessors;
import com.bfsuol.bfsuolframework.core.utils.StringUtils;
import java.util.ArrayList;
import java.util.List;

@TableName("t_sec_role_privilege")
@Data
@Accessors(chain = true)
public class RolePrivilege extends EntitySupport implements Entity {

    private static final long serialVersionUID = 1L;

    public RolePrivilege(){}
    public RolePrivilege(Long id){
        this.id = id;
    }

    @TableId(type = IdType.AUTO,value = "role_privilege_id")
    private Long id;
    @TableField(exist = false)
    private Role role;//所属角色
    @TableField(value = "role_id")
    private Long roleId;
    @TableField(value = "privilege_title")
    private String privilegeTitle;//权限名称
    @TableField(value = "privilege_code")
    private String privilegeCode;//权限编码
    @TableField(value = "function_list")
    private String functionList;//功能编码列表

    /**
     * @return 功能编码列表集合
     */
    public List<String> getFunctions() {
        if(!StringUtils.isBlank(this.functionList)){
            return StringUtils.splitToList(this.functionList, "\\|");
        }
        return new ArrayList<String>();
    }

    public boolean isNew() {
        return getId() == null || getId().longValue()<=0;
    }
}

